<!--
	Copyright (C) 2010 Ethan Gruber
	EADitor: http://code.google.com/p/eaditor/
	Apache License 2.0: http://code.google.com/p/eaditor/
	
	Heavily modified from exist sandbox form developed by Orbeon	
-->
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xi="http://www.w3.org/2001/XInclude"
	xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:ead="urn:isbn:1-931666-22-9">
	<xhtml:head>
		<xhtml:title>EADitor: Manage Controlled Vocabularies</xhtml:title>
		<xhtml:link rel="stylesheet" type="text/css" href="/apps/eaditor/css/grids-min.css"/>
		<xhtml:link rel="stylesheet" type="text/css" href="/apps/eaditor/css/reset-fonts-grids.css"/>
		<xhtml:link rel="stylesheet" type="text/css" href="/apps/eaditor/css/base-min.css"/>
		<xhtml:link rel="stylesheet" type="text/css" href="/apps/eaditor/css/fonts-min.css"/>

		<!-- EADitor styling -->
		<xhtml:link rel="stylesheet" href="/apps/eaditor/css/style.css"/>
		<xhtml:link rel="stylesheet" href="/apps/eaditor/css/themes/smoothness.css"/>
		
		<xhtml:script type="text/javascript" src="/apps/eaditor/javascript/jquery-1.4.2.min.js"/>
		<xhtml:script type="text/javascript" src="/apps/eaditor/javascript/menu.js"/>
		<xforms:model>
			<xforms:instance id="exist-url">
				<xi:include href="exist-url.xml"/>
			</xforms:instance>
			
			<xforms:instance id="control-instance">
				<control xmlns="">
					<term>subject</term>
					<resource>eaditor/guides/</resource>
					<query/>
					<error/>
					<formatted-result/>
				</control>
			</xforms:instance>

			<xforms:bind nodeset="instance('control-instance')">
				<xforms:bind nodeset="formatted-result"
					calculate="if (instance('response-instance')/*)
					then xxforms:serialize(xxforms:call-xpl('oxf:/apps/eaditor/xpl/format-terms.xpl', 'data', instance('response-instance')/*[1], 'data')/*, 'html')
					else ''"
				/>
			</xforms:bind>

			<xforms:instance id="config">
				<config xmlns="">
					<lcsh-date/>
				</config>
			</xforms:instance>

			<xforms:instance id="created-template">
				<field name="created"/>
			</xforms:instance>

			<xforms:instance id="modified-template">
				<field name="modified"/>
			</xforms:instance>

			<xforms:instance id="status">
				<status/>
			</xforms:instance>

			<xforms:instance id="current-term">
				<current xmlns="">
					<term/>
				</current>
			</xforms:instance>

			<xforms:instance id="lcsh-feed">
				<feed xmlns=""/>
			</xforms:instance>

			<!-- send to Solr -->
			<xforms:instance id="addIndex">
				<add xmlns=""/>
			</xforms:instance>

			<!-- Instance for Solr commit-->
			<xforms:instance id="sendCommit">
				<commit/>
			</xforms:instance>

			<xforms:instance id="optimizeIndex">
				<optimize/>
			</xforms:instance>

			<xforms:instance id="solrDoc-template">
				<doc xmlns="">
					<field name="id"/>
					<field name="source"/>
				</doc>
			</xforms:instance>

			<xforms:instance id="corpname-template">
				<field name="corpname"/>
			</xforms:instance>
			<xforms:instance id="famname-template">
				<field name="famname"/>
			</xforms:instance>
			<xforms:instance id="genreform-template">
				<field name="genreform"/>
			</xforms:instance>
			<xforms:instance id="geogname-template">
				<field name="geogname"/>
			</xforms:instance>
			<xforms:instance id="persname-template">
				<field name="persname"/>
			</xforms:instance>
			<xforms:instance id="subject-template">
				<field name="subject"/>
			</xforms:instance>

			<xforms:instance id="solrResponse">
				<response xmlns=""/>
			</xforms:instance>

			<xforms:instance id="termtype-instance">
				<type xmlns="">
					<term>subject</term>
				</type>
			</xforms:instance>

			<!-- purge list -->
			<xforms:instance id="purge-list">
				<terms xmlns=""/>
			</xforms:instance>
			<xforms:instance id="terms-list">
				<terms xmlns="">
					<term type="corpname">Corporate Names</term>
					<term type="famname">Family Names</term>
					<term type="genreform">Genreforms</term>
					<term type="geogname">Geographical Names</term>
					<term type="persname">Personal Names</term>
					<term type="subject">Subject</term>
				</terms>
			</xforms:instance>

			<!-- Solr purge instances -->
			<xforms:instance id="delete-corpname">
				<delete>
					<query>source:local AND corpname:*</query>
				</delete>
			</xforms:instance>
			<xforms:instance id="delete-famname">
				<delete>
					<query>source:local AND famname:*</query>
				</delete>
			</xforms:instance>
			<xforms:instance id="delete-genreform">
				<delete>
					<query>source:local AND genreform:*</query>
				</delete>
			</xforms:instance>
			<xforms:instance id="delete-geogname">
				<delete>
					<query>source:local AND geogname:*</query>
				</delete>
			</xforms:instance>
			<xforms:instance id="delete-persname">
				<delete>
					<query>source:local AND persname:*</query>
				</delete>
			</xforms:instance>
			<xforms:instance id="delete-subject">
				<delete>
					<query>source:local AND subject:*</query>
				</delete>
			</xforms:instance>

			<!-- eXist query instances -->
			<xforms:instance id="corpname-instance">
				<exist:query xmlns="">
					<exist:text>&lt;report> { for $foo in collection() return $foo//*[local-name()='corpname'] } &lt;/report></exist:text>
				</exist:query>
			</xforms:instance>
			<xforms:instance id="famname-instance">
				<exist:query xmlns="">
					<exist:text>&lt;report> { for $foo in collection() return $foo//*[local-name()='famname'] } &lt;/report></exist:text>
				</exist:query>
			</xforms:instance>
			<xforms:instance id="genreform-instance">
				<exist:query xmlns="">
					<exist:text>&lt;report> { for $foo in collection() return $foo//*[local-name()='genreform'] } &lt;/report></exist:text>
				</exist:query>
			</xforms:instance>
			<xforms:instance id="geogname-instance">
				<exist:query xmlns="">
					<exist:text>&lt;report> { for $foo in collection() return $foo//*[local-name()='geogname'] } &lt;/report></exist:text>
				</exist:query>
			</xforms:instance>
			<xforms:instance id="persname-instance">
				<exist:query xmlns="">
					<exist:text>&lt;report> { for $foo in collection() return $foo//*[local-name()='persname'] } &lt;/report></exist:text>
				</exist:query>
			</xforms:instance>
			<xforms:instance id="subject-instance">
				<exist:query xmlns="">
					<exist:text>&lt;report> { for $foo in collection() return $foo//*[local-name()='subject'] } &lt;/report></exist:text>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="response-instance">
				<exist:result/>
			</xforms:instance>

			<!-- submit query to eXist -->
			<xforms:submission id="corpname-submission" ref="instance('corpname-instance')" action="{instance('exist-url')}{instance('control-instance')/resource}" method="post"
				replace="instance" instance="response-instance"/>
			<xforms:submission id="famname-submission" ref="instance('famname-instance')" action="{instance('exist-url')}{instance('control-instance')/resource}" method="post"
				replace="instance" instance="response-instance"/>
			<xforms:submission id="genreform-submission" ref="instance('genreform-instance')" action="{instance('exist-url')}{instance('control-instance')/resource}" method="post"
				replace="instance" instance="response-instance"/>
			<xforms:submission id="geogname-submission" ref="instance('geogname-instance')" action="{instance('exist-url')}{instance('control-instance')/resource}" method="post"
				replace="instance" instance="response-instance"/>
			<xforms:submission id="persname-submission" ref="instance('persname-instance')" action="{instance('exist-url')}{instance('control-instance')/resource}" method="post"
				replace="instance" instance="response-instance"/>
			<xforms:submission id="subject-submission" ref="instance('subject-instance')" action="{instance('exist-url')}{instance('control-instance')/resource}" method="post"
				replace="instance" instance="response-instance"/>

			<!-- purge existing terms before adding new ones -->
			<xforms:submission id="delete-corpname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('delete-corpname')" instance="delete-corpname"
				replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
			</xforms:submission>
			<xforms:submission id="delete-famname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('delete-famname')" instance="delete-famname" replace="none"
				method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
			</xforms:submission>
			<xforms:submission id="delete-genreform-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('delete-genreform')" instance="delete-genreform"
				replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
			</xforms:submission>
			<xforms:submission id="delete-geogname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('delete-geogname')" instance="delete-geogname"
				replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
			</xforms:submission>
			<xforms:submission id="delete-persname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('delete-persname')" instance="delete-persname"
				replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
			</xforms:submission>
			<xforms:submission id="delete-subject-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('delete-subject')" instance="delete-subject" replace="none"
				method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
			</xforms:submission>

			<!-- post to solr -->
			<xforms:submission id="post-corpname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Corporate Names added to index.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>
			<xforms:submission id="post-famname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Family Names added to index.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>
			<xforms:submission id="post-genreform-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Genres/Formats added to index.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>
			<xforms:submission id="post-geogname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Geographical Names added to index.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>
			<xforms:submission id="post-persname-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Personal Names added to index.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>
			<xforms:submission id="post-subject-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Subjects added to index.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>
			<xforms:submission id="post-lcsh-submission" action="{instance('config')/solr_vocabularies}update" ref="instance('addIndex')" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>

			<!-- get updated LCSH terms -->
			<xforms:submission id="update-lcsh" serialization="none" method="get" action="http://id.loc.gov/authorities/feed/page/1/" replace="instance" instance="lcsh-feed">
				<xforms:insert ev:event="xforms-submit-done" nodeset="instance('addIndex')" origin="xxforms:call-xpl('oxf:/apps/eaditor/xpl/update_lcsh.xpl', 'data', instance('lcsh-feed'), 'data')"/>
				<xforms:message ev:event="xforms-submit-error" level="modal">Unable to process feed. id.loc.gov may be down.</xforms:message>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')" value="concat(count(instance('addIndex')//doc), ' records received from id.loc.gov.')"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('config')/lcsh-date" value="local-dateTime()"/>
				<xforms:send ev:event="xforms-submit-done" submission="post-lcsh-submission"/>
				<xforms:send ev:event="xforms-submit-done" submission="update-config"/>
			</xforms:submission>

			<!-- Load the EADitor config file into an instance to extract the date of the last LCSH update -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-url')}eaditor/config.xml" replace="instance" instance="config"/>

			<xforms:submission id="update-config" ref="instance('config')" action="{instance('exist-url')}eaditor/config.xml" method="put" replace="none">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error update EADitor config file.</xforms:message>
			</xforms:submission>

			<!-- send commit -->
			<xforms:submission id="submit-commit" action="{instance('config')/solr_vocabularies}update" ref="instance('sendCommit')" instance="sendCommit" replace="none" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr!</xforms:message>
			</xforms:submission>

			<!-- send optimize -->
			<xforms:submission id="optimize-vocabularies" action="{instance('config')/solr_vocabularies}update" ref="instance('optimizeIndex')" instance="optimizeIndex" replace="none"
				method="post">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Index optimized.</xforms:setvalue>
				<xforms:message ev:event="xforms-submit-error" level="modal">Failed to optimize!</xforms:message>
			</xforms:submission>

			<xforms:setvalue ev:event="xforms-submit-error" ref="instance('control-instance')/error" value="event('response-body')"/>

			<!-- load eaditor config file on xforms construction -->
			<xforms:send ev:event="xforms-model-construct-done" submission="load-config"/>

			<!-- querying existing terms -->
			<xforms:instance id="term-template">
				<term/>
			</xforms:instance>

			<xforms:instance id="suggest-query">
				<query/>
			</xforms:instance>

			<!-- Instance with the suggestions we get back from Solr -->
			<xforms:instance id="suggestions">
				<suggestions/>
			</xforms:instance>

			<xforms:submission id="suggest" serialization="none" method="get"
				action="{instance('config')/solr_vocabularies}terms?terms.fl={instance('termtype-instance')/term}&amp;terms.limit=10&amp;terms.sort=index&amp;terms.prefix={instance('suggest-query')}"
				instance="suggestions" replace="instance"/>

			<xforms:submission id="get-doc" serialization="none" method="get"
				action="{instance('config')/solr_vocabularies}select?q={instance('termtype-instance')/term}:&#x022;{instance('term-template')}&#x022;" instance="solrResponse"
				replace="instance">
				<xforms:action ev:event="xforms-submit-done">
					<xforms:action if="instance('solrResponse')/result/doc/str[@name='source'] = 'lcsh' or instance('solrResponse')/result/doc/str[@name='source'] = 'lcgft'">
						<xforms:toggle case="lcsh" ev:event="DOMActivate"/>
					</xforms:action>
					<xforms:action if="instance('solrResponse')/result/doc/str[@name='source'] = 'local'">
						<xforms:toggle case="non-lcsh" ev:event="DOMActivate"/>
					</xforms:action>
				</xforms:action>
			</xforms:submission>
		</xforms:model>
	</xhtml:head>
	<xhtml:body class="yui-skin-sam">
		<xhtml:div id="doc4">
			<!-- header -->
			<xxforms:variable name="display_path">../../</xxforms:variable><xi:include href="header-admin.xml"/>

			<xhtml:div id="bd">
				<xforms:group ref="instance('status')/text()">
					<xhtml:div class="success">
						<xforms:output ref="instance('status')"/>
					</xhtml:div>
				</xforms:group>
				<p>
					<a href="..">&lt; Return</a>
				</p>
				<xhtml:h2>Manage Controlled Vocabularies</xhtml:h2>
				<p>You can use this form to scrape controlled vocabulary terms from all EAD guides in the eXist database and add the terms into the Solr vocabularies index. Eventually one will be able
					to create custom vocabularies and edit existing ones.</p>
				<widget:tabs>
					<widget:tab id="update">
						<widget:label>Update LCSH</widget:label>
						<xhtml:div class="section">
							<xhtml:h3>Update LCSH terms from Atom Feed</xhtml:h3>
							<p>This function enables querying the Library of Congress's LCSH service at id.loc.gov to extract terms from the Atom feed that have been created or updated since the
								previous date this function was run. This may take several minutes.</p>
							<p>Date of last update: <xforms:output ref="instance('config')/lcsh-date"/></p>
							<p>
								<xforms:trigger>
									<xforms:label>Update Terms</xforms:label>
									<xforms:action ev:event="DOMActivate">
										<xforms:send submission="update-lcsh"/>
									</xforms:action>
								</xforms:trigger>
							</p>
						</xhtml:div>
					</widget:tab>
					<widget:tab id="import">
						<widget:label>Import</widget:label>
						<xhtml:div class="section">
							<xhtml:h3>Import Local Terms</xhtml:h3>
							<xhtml:div style="display:table;">
								<xforms:select1 ref="instance('control-instance')/term">
									<xforms:label>Term Type</xforms:label>
									<xforms:itemset nodeset="instance('terms-list')/term">
										<xforms:label ref="."/>
										<xforms:value ref="@type"/>
									</xforms:itemset>
								</xforms:select1>
								<xforms:trigger>
									<xforms:label>List Terms</xforms:label>
									<xforms:action ev:event="DOMActivate">
										<xforms:setvalue ref="instance('current-term')/term" value="instance('control-instance')/term"/>
										<xforms:send if="instance('control-instance')/term = 'corpname'" submission="corpname-submission"/>
										<xforms:send if="instance('control-instance')/term = 'famname'" submission="famname-submission"/>
										<xforms:send if="instance('control-instance')/term = 'genreform'" submission="genreform-submission"/>
										<xforms:send if="instance('control-instance')/term = 'geogname'" submission="geogname-submission"/>
										<xforms:send if="instance('control-instance')/term = 'persname'" submission="persname-submission"/>
										<xforms:send if="instance('control-instance')/term = 'subject'" submission="subject-submission"/>
									</xforms:action>
								</xforms:trigger>
							</xhtml:div>
							<xforms:group ref="instance('response-instance')/report/*">
								<xhtml:div class="term_results">
									<!--<xforms:group ref="count(instance('response-instance')/report/node()) &gt; 10">
									<xhtml:span style="float:right">more</xhtml:span>
									</xforms:group>-->
									<xforms:output ref="instance('control-instance')/formatted-result" mediatype="text/html"/>
									<br/>
									<p>
										<xforms:trigger>
											<xforms:label>Add to Index</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<!-- convert response instance into a solr doc -->
												<xforms:insert nodeset="instance('addIndex')"
													origin="xxforms:call-xpl('oxf:/apps/eaditor/xpl/terms-to-solr.xpl', 'data', instance('response-instance'), 'data')"/>
												<!--<xforms:setvalue ref="instance('created-template')"
												value="local-dateTime()"/>
											<xforms:setvalue ref="instance('modified-template')"
												value="local-dateTime()"/>-->
												<!-- iterate through each doc in addIndex to add created and modified dates -->
												<!--<xforms:action
												xxforms:iterate="instance('addIndex')/doc">												
												<xforms:insert context="." node
												origin="instance('created-template')"/>
												<xforms:insert context="."
												origin="instance('modified-template')"/>
											</xforms:action>-->
												<!-- purge existing terms in that category first -->
												<xforms:send if="instance('current-term')/term = 'corpname'" submission="delete-corpname-submission"/>
												<xforms:send if="instance('current-term')/term = 'famname'" submission="delete-famname-submission"/>
												<xforms:send if="instance('current-term')/term = 'genreform'" submission="delete-genreform-submission"/>
												<xforms:send if="instance('current-term')/term = 'geogname'" submission="delete-geogname-submission"/>
												<xforms:send if="instance('current-term')/term = 'persname'" submission="delete-persname-submission"/>
												<xforms:send if="instance('current-term')/term = 'subject'" submission="delete-subject-submission"/>
												<!-- add terms to solr -->
												<xforms:send if="instance('current-term')/term = 'corpname'" submission="post-corpname-submission"/>
												<xforms:send if="instance('current-term')/term = 'famname'" submission="post-famname-submission"/>
												<xforms:send if="instance('current-term')/term = 'genreform'" submission="post-genreform-submission"/>
												<xforms:send if="instance('current-term')/term = 'geogname'" submission="post-geogname-submission"/>
												<xforms:send if="instance('current-term')/term = 'persname'" submission="post-persname-submission"/>
												<xforms:send if="instance('current-term')/term = 'subject'" submission="post-subject-submission"/>
											</xforms:action>
										</xforms:trigger>
									</p>
								</xhtml:div>
							</xforms:group>
						</xhtml:div>
					</widget:tab>
					<widget:tab id="custom">
						<widget:label>Create/Edit</widget:label>
						<xhtml:div class="section">
							<xhtml:h3>Edit Terms</xhtml:h3>
							<xhtml:div style="display:table">
								<xforms:select1 ref="instance('termtype-instance')/term" appearance="full">
									<xforms:label>Term Type</xforms:label>
									<xforms:itemset nodeset="instance('terms-list')/term">
										<xforms:label ref="."/>
										<xforms:value ref="@type"/>
									</xforms:itemset>
									<xforms:action ev:event="xforms-value-changed">
										<xforms:delete nodeset="instance('solrResponse')/*"/>
									</xforms:action>
								</xforms:select1>
							</xhtml:div>
							<xhtml:div style="margin-top:10px;display:table;width:100%">
								<fr:autocomplete ref="instance('term-template')" dynamic-itemset="true">
									<xforms:action ev:event="fr-search-changed">
										<xxforms:variable name="search-value" select="event('fr-search-value')"/>
										<xxforms:variable name="make-suggestion" select="string-length($search-value) >= 2"/>
										<xforms:action if="$make-suggestion">
											<xforms:setvalue ref="instance('suggest-query')" value="$search-value"/>
											<xforms:send submission="suggest"/>
											<xforms:action if="not($make-suggestion)">
												<xforms:delete nodeset="instance('suggestions')//lst[@name='terms']/lst/int"/>
											</xforms:action>
										</xforms:action>
									</xforms:action>
									<xforms:label style="float:left">Term</xforms:label>
									<xforms:itemset nodeset="instance('suggestions')/lst[@name='terms']/lst/int">
										<xforms:label ref="@name"/>
										<xforms:value ref="@name"/>
									</xforms:itemset>
								</fr:autocomplete>
								<xforms:group ref="instance('term-template')/text()">
									<xforms:trigger appearance="minimal" style="margin-left:10px;">
										<xforms:label><xhtml:img src="/apps/eaditor/images/recycle-green.png" alt="Load"/>Load</xforms:label>
										<xforms:action ev:event="DOMActivate">
											<xforms:send submission="get-doc"/>
										</xforms:action>
									</xforms:trigger>
								</xforms:group>
							</xhtml:div>
							<xforms:group ref="instance('solrResponse')/result/doc">
								<xhtml:div style="margin-top:20px;">
									<xforms:switch>
										<xforms:case id="lcsh">
											<xhtml:div class="warning">
												<xhtml:h4>Warning: LCSH terms are prohibited from being edited manually.</xhtml:h4>
												<xhtml:div>
													<xforms:output ref="str[@name='id']">
														<xforms:label>Id</xforms:label>
													</xforms:output>
												</xhtml:div>
												<xforms:group ref=".[count(str[@name='subject']) &gt; 0]">
													<xhtml:div>
														<xforms:output ref="str[@name='subject']">
															<xforms:label>Subject</xforms:label>
														</xforms:output>
													</xhtml:div>
												</xforms:group>
												<xforms:group ref=".[count(str[@name='genreform']) &gt; 0]">
													<xhtml:div>
														<xforms:output ref="str[@name='genreform']">
															<xforms:label>Genre/Form</xforms:label>
														</xforms:output>
													</xhtml:div>
												</xforms:group>
												<xhtml:div>
													<xforms:output ref="str[@name='source']">
														<xforms:label>Source</xforms:label>
													</xforms:output>
												</xhtml:div>
												<xhtml:div>
													<xforms:output ref="str[@name='created']">
														<xforms:label>Created</xforms:label>
													</xforms:output>
												</xhtml:div>
												<xhtml:div>
													<xforms:output ref="str[@name='modified']">
														<xforms:label>Modified</xforms:label>
													</xforms:output>
												</xhtml:div>
											</xhtml:div>
										</xforms:case>
										<xforms:case id="non-lcsh">
											<xxforms:variable name="termtype" select="instance('termtype-instance')/term"/>
											<xxforms:variable name="termlabel"
												select="substring(instance('terms-list')/term[@type = instance('termtype-instance')/term]/text(), 1, string-length(instance('terms-list')/term[@type = instance('termtype-instance')/term]/text()) - 1)"/>
											<xhtml:div>
												<xforms:output ref="str[@name='id']">
													<xforms:label>Id</xforms:label>
												</xforms:output>
											</xhtml:div>
											<xhtml:div>
												<xforms:output ref="str[@name='source']">
													<xforms:label>Source</xforms:label>
												</xforms:output>
											</xhtml:div>
											<xhtml:div>
												<xforms:output ref="str[@name='created']">
													<xforms:label>Created</xforms:label>
												</xforms:output>
											</xhtml:div>
											<xhtml:div>
												<xforms:output ref="str[@name='modified']">
													<xforms:label>Modified</xforms:label>
												</xforms:output>
											</xhtml:div>
											<xhtml:div>
												<xforms:input ref="str[@name=$termtype]">
													<xforms:label>
														<xforms:output ref="$termlabel"/>
													</xforms:label>
												</xforms:input>
											</xhtml:div>
											<!--<xforms:trigger appearance="minimal">
											<xforms:label><xhtml:img src="/apps/eaditor/images/save.gif"
												alt="Save"/>Save</xforms:label>
											<xforms:insert ev:event="DOMActivate" context="."
												nodeset="eadheader/child::node()[last()]"
												origin="instance('profiledesc-template')"/>
											<xforms:action ev:event="DOMActivate">
												<xforms:send submission="get-doc"/>
											</xforms:action>
										</xforms:trigger>-->
										</xforms:case>
									</xforms:switch>
								</xhtml:div>
							</xforms:group>
						</xhtml:div>
					</widget:tab>
					<widget:tab id="purge">
						<widget:label>Purge</widget:label>
						<xhtml:div class="section">
							<xhtml:h3>Purge Terms</xhtml:h3>
							<xhtml:div style="display:table">
								<xforms:select ref="instance('purge-list')" appearance="full">
									<xforms:label>Select terms to purge:</xforms:label>
									<xforms:itemset nodeset="instance('terms-list')/term">
										<xforms:label ref="."/>
										<xforms:value ref="@type"/>
									</xforms:itemset>
								</xforms:select>
							</xhtml:div>
							<xforms:trigger>
								<xforms:label>Purge Terms</xforms:label>
								<xforms:action ev:event="DOMActivate">
									<!-- purge terms -->
									<xforms:send if="contains(instance('purge-list'), 'corpname')" submission="delete-corpname-submission"/>
									<xforms:send if="contains(instance('purge-list'), 'famname')" submission="delete-famname-submission"/>
									<xforms:send if="contains(instance('purge-list'), 'genreform')" submission="delete-genreform-submission"/>
									<xforms:send if="contains(instance('purge-list'), 'geogname')" submission="delete-geogname-submission"/>
									<xforms:send if="contains(instance('purge-list'), 'persname')" submission="delete-persname-submission"/>
									<xforms:send if="contains(instance('purge-list'), 'subject')" submission="delete-subject-submission"/>
									<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Terms purged.</xforms:setvalue>
								</xforms:action>
							</xforms:trigger>
						</xhtml:div>
					</widget:tab>
					<widget:tab id="optimize">
						<widget:label>Optimize</widget:label>
						<xhtml:div class="section">
							<xhtml:h3>Optimize Vocabulary Index</xhtml:h3>
							<p>Use this feature to optimize the controlled vocabulary Solr index for maximum efficiency. Optimization takes several minutes and is only required on occasion.</p>
							<p>
								<xforms:trigger>
									<xforms:label>Optimize</xforms:label>
									<xforms:action ev:event="DOMActivate">
										<xforms:send submission="optimize-vocabularies"/>
									</xforms:action>
								</xforms:trigger>
							</p>
						</xhtml:div>
					</widget:tab>
				</widget:tabs>
				<!--<widget:xforms-instance-inspector id="orbeon-xforms-inspector"
				xmlns:widget="http://orbeon.org/oxf/xml/widget"/>-->
			</xhtml:div>

			<!-- footer -->
			<xi:include href="xslt/footer.xml"/>
		</xhtml:div>
	</xhtml:body>
</xhtml:html>
